/*
#include "audio_resource.h"
#include "ogg/include/vorbis/codec.h"
#include "ogg/include/vorbis/vorbisfile.h"

// resouce manager
#include "resman/resman.h"
#include "util/log.h"				// log
#include "util/common_macros.h"		// macros
#include "util/mmgr.h"		    

// VFS
#include "vfs/vfs.h"

#include <cassert>
using namespace audio;


namespace 
{
	class	AutoReg
	{
	public:
		AutoReg()
		{
			res::ResMan& RM = res::ResMan::Instance();
			RM.AddResourceConstructor(AudioResource::CreateAudioResource, "ogg");
			_LOG(MSG_INIT, "File formats registered for audio");
		}
	} AutoReg;
};

res::Resource*	AudioResource::CreateAudioResource()
{
	// construct
	return new AudioResource();
}


AudioResource::AudioResource() :
	Resource(),
	m_pBuffer(NULL),
	m_BufferSize(NULL),
	m_Stereo(false)
{
	
}

AudioResource::~AudioResource()
{

}

static size_t ReadCB(void *ptr, size_t size, size_t nmemb, void *datasource)
{
	vfs::LoadedBlock* pData = (vfs::LoadedBlock*)datasource;
	assert(pData);

	int	DataSize = size*nmemb;
	int	RemainSize = pData->Size - pData->Index;
	int Count  = nmemb;
	if (DataSize > RemainSize)
	{
		// load the largest size we can get away with
		Count = RemainSize / size;
	}

	memcpy(ptr, &pData->DataArray[pData->Index], Count * size);
	pData->Index+=Count * size;
	return Count;
}

static int	  SeekCB(void *datasource, ogg_int64_t offset, int whence)
{
	vfs::LoadedBlock* pData = (vfs::LoadedBlock*)datasource;
	assert(pData);

	switch (whence)
	{
		case SEEK_CUR:
			if (pData->Index + offset >= pData->Size || pData->Index + offset < 0)
				return -1;
			pData->Index+=(int)offset;
			break;
		case SEEK_END:
			if (offset > pData->Size || offset < 0)
				return -1;
			pData->Index = pData->Size - (int)offset;
			break;
		case SEEK_SET:
			if (offset >= pData->Size || offset < 0)
				return - 1;
			pData->Index = (int)offset;
			break;
	}
	return 0;
}

static int    CloseCB(void *datasource)
{
	vfs::LoadedBlock* pData = (vfs::LoadedBlock*)datasource;
	assert(pData);

	// does nothing.. the datasource will be deleted later anyways
	return 0;
}

static long   TellCB(void *datasource)
{
	vfs::LoadedBlock* pData = (vfs::LoadedBlock*)datasource;
	assert(pData);
	
	return pData->Index;
}


void	AudioResource::InitializeResource()
{
	HRESULT hRes = S_OK;
	if (m_State != RS_CACHED)
	{
		_LOG(MSG_WARNING, "Audio file " << m_Name << " not yet loaded!");
		return;
	}

	m_Data.ResetIndex();

	ov_callbacks	CB;
	OggVorbis_File oggFile;

	CB.read_func = ReadCB;
	CB.seek_func = SeekCB;
	CB.tell_func = TellCB;
	CB.close_func = CloseCB;

	int Res = ov_open_callbacks(&m_Data, &oggFile,0, 0, CB);

	if (Res == 0)
	{
		// we read the file successfully..
		// now it's time to generate our unpacked data buffer

		vorbis_info*	pInfo = ov_info(&oggFile, -1);

		// get some usefull info
		if (pInfo->channels > 1) m_Stereo = true;
		m_Frequency = pInfo->rate;

		int	Samples = (int)ov_pcm_total(&oggFile, -1);
		if (Samples > 0)
		{
			m_BufferSize = Samples * 2;	// 16bit per sample
			m_pBuffer = new char[m_BufferSize];
			
			int Index = 0;
			int BytesRead;
			do
			{
				int Bitstream = 0;
				BytesRead = ov_read(&oggFile, 
									&m_pBuffer[Index],			// destination buffer
									m_BufferSize-Index,			// max size to rad
									0,							// little endian
									2,							// word size (16 bit)
									1,							// signed data
									&Bitstream);				// pointer to current bitstream.
				Index += BytesRead;
			} while (BytesRead > 0);
			int j = 0;
		}

		ov_clear(&oggFile);
	} else
	{
		_LOG(MSG_ERROR, "Unable to open OGG file " << m_Name);
	}
	// remember to free resource at the end of the process
	UTIL_SAFE_DELETEA(m_Data.DataArray);
}

void	AudioResource::ReleaseResource()
{
	UTIL_SAFE_DELETEA(m_pBuffer);
	m_State = RS_RELEASED;
}
*/
